home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / BASICS.ZIP / CLASSLIB / FRAMEWIN.CPP < prev    next >
C/C++ Source or Header  |  1993-03-23  |  8KB  |  380 lines

  1. /*
  2.  * FRAMEWIN.CPP
  3.  * Sample Code Class Libraries
  4.  *
  5.  * Frame window procedure used with the CFrame class as well as the
  6.  * implementation of CDocumentAdviseSink that the frame is interested in.
  7.  *
  8.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Software Design Engineer
  11.  * Microsoft Systems Developer Relations
  12.  *
  13.  * Internet  :  kraigb@microsoft.com
  14.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  15.  */
  16.  
  17.  
  18.  
  19. #include <windows.h>
  20. #include "classlib.h"
  21.  
  22.  
  23.  
  24.  
  25. /*
  26.  * FrameWndProc
  27.  *
  28.  * Purpose:
  29.  *  Frame window class procedure that allows a derivation of these
  30.  *  classes to hook and process any messages desired.  Otherwise this
  31.  *  handles standard commands as well as the status line and menus.
  32.  */
  33.  
  34. LRESULT FAR PASCAL __export FrameWndProc(HWND hWnd, UINT iMsg
  35.     , WPARAM wParam, LPARAM lParam)
  36.     {
  37.     LPCFrame        pFR;
  38.     LPCClient       pCL=NULL;
  39.     WORD            dx, dy;
  40.     LRESULT         lRet;
  41.  
  42.     //This will be valid for all messages except WM_NCCREATE
  43.     pFR=(LPCFrame)GetWindowLong(hWnd, FRAMEWL_STRUCTURE);
  44.  
  45.     if (NULL!=pFR)
  46.         {
  47.         //Call the hook and return its value if it tells us to.
  48.         if (pFR->FMessageHook(hWnd, iMsg, wParam, lParam, &lRet))
  49.             return lRet;
  50.  
  51.         //Otherwise copy the CClient pointer and continue.
  52.         pCL=pFR->m_pCL;
  53.         }
  54.  
  55.     switch (iMsg)
  56.         {
  57.         case WM_NCCREATE:
  58.             //CreateWindow passed pFR to us.
  59.             pFR=(LPCFrame)((LONG)((LPCREATESTRUCT)lParam)->lpCreateParams);
  60.  
  61.             //Store with the window--UINT converts to 32-bits.
  62.             SetWindowLong(hWnd, FRAMEWL_STRUCTURE, (LONG)(LPSTR)pFR);
  63.             return DefWindowProc(hWnd, iMsg, wParam, lParam);
  64.  
  65.         case WM_DESTROY:
  66.             PostQuitMessage(0);
  67.             break;
  68.  
  69.         //Don't close if any children cancel the operation.
  70.         case WM_CLOSE:
  71.             pFR->m_fClosing=TRUE;
  72.  
  73.             if (!pCL->QueryCloseAllDocuments(TRUE))
  74.                 {
  75.                 pFR->m_fClosing=FALSE;
  76.                 break;
  77.                 }
  78.  
  79.             //Destroy everything.
  80.             DestroyWindow(hWnd);
  81.             break;
  82.  
  83.  
  84.         case WM_QUERYENDSESSION:
  85.             return pCL->QueryCloseAllDocuments(TRUE);
  86.  
  87.  
  88.        #ifdef NEVER
  89.         case WM_ERASEBKGND:
  90.             //Our client area is never visible, so don't flash
  91.             return TRUE;
  92.        #endif
  93.  
  94.  
  95.         case WM_SIZE:
  96.             pFR->m_fSizing=TRUE;
  97.             dx=LOWORD(lParam);
  98.             dy=HIWORD(lParam);
  99.  
  100.             //Change the gizmobar and StatStrip widths to match
  101.             pFR->m_pGB->OnSize(hWnd);
  102.             pFR->m_pSS->OnSize(hWnd);
  103.  
  104.             pCL->OnSize(0, pFR->m_cyBar, dx, dy-pFR->m_cyBar-CYSTATSTRIP);
  105.  
  106.             pFR->m_fSizing=FALSE;
  107.             break;
  108.  
  109.  
  110.         case WM_INITMENUPOPUP:
  111.             //Skip the system menu
  112.             if (TRUE==(BOOL)HIWORD(lParam))
  113.                 break;
  114.  
  115.             //Go handle graying menu items appropriately.
  116.             pFR->UpdateMenus((HMENU)wParam, (UINT)LOWORD(lParam));
  117.             break;
  118.  
  119.  
  120.         case WM_MENUSELECT:
  121.             pFR->m_pSS->MenuSelect(wParam, lParam);
  122.             break;
  123.  
  124.  
  125.         case WM_DESTROYCLIPBOARD:
  126.             //When we empty contents, disable the paste button
  127.             pFR->m_pGB->Enable(IDM_EDITPASTE, FALSE);
  128.             break;
  129.  
  130.  
  131.         case WM_COMMAND:
  132.             return pFR->OnCommand(hWnd, wParam, lParam);
  133.  
  134.  
  135.         default:
  136.             //Don't try using CClient unless we have one.
  137.             if (NULL!=pCL)
  138.                 return pCL->DefaultFrameProc(hWnd, iMsg, wParam, lParam);
  139.             else
  140.                 return DefWindowProc(hWnd, iMsg, wParam, lParam);
  141.         }
  142.  
  143.     return 0L;
  144.     }
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. /*
  152.  * AboutProc
  153.  *
  154.  * Purpose:
  155.  *  Dialog procedure for the omnipresent About box.
  156.  *
  157.  * Parameters:
  158.  *  The standard.
  159.  *
  160.  * Return Value:
  161.  *  The value to be returned through the DialogBox call that
  162.  *  created the dialog.
  163.  *
  164.  */
  165.  
  166. BOOL __export FAR PASCAL AboutProc(HWND hDlg, UINT iMsg
  167.     , WPARAM wParam, LPARAM lParam)
  168.     {
  169.     switch (iMsg)
  170.         {
  171.         case WM_INITDIALOG:
  172.             return TRUE;
  173.  
  174.         case WM_COMMAND:
  175.             switch (LOWORD(wParam))
  176.                 {
  177.                 case IDOK:
  178.                 case IDCANCEL:
  179.                     EndDialog(hDlg, TRUE);
  180.                 }
  181.             break;
  182.         }
  183.     return FALSE;
  184.     }
  185.  
  186.  
  187.  
  188.  
  189.  
  190. //CDocumentAdviseSink implementation for the frame window.
  191.  
  192.  
  193.  
  194. /*
  195.  * CDocumentAdviseSink::CDocumentAdviseSink
  196.  *
  197.  * Purpose:
  198.  *  Constructs an advise object storing a pointer for the caller's use.
  199.  *
  200.  * Parameters:
  201.  *  pv              LPVOID to store in this object
  202.  */
  203.  
  204. CDocumentAdviseSink::CDocumentAdviseSink(LPVOID pv)
  205.     {
  206.     m_pv=pv;
  207.     return;
  208.     }
  209.  
  210.  
  211.  
  212.  
  213. /*
  214.  * CDocumentAdviseSink::OnDataChange
  215.  *
  216.  * Purpose:
  217.  *  Informs the frame that document data changed so we may need to
  218.  *  update some of our UI.
  219.  *
  220.  * Parameters:
  221.  *  pDoc            LPCDocument notifying us.
  222.  *
  223.  * Return Value:
  224.  *  None
  225.  */
  226.  
  227. void CDocumentAdviseSink::OnDataChange(LPCDocument pDoc)
  228.     {
  229.     LPCFrame    pFR=(LPCFrame)m_pv;
  230.  
  231.     pFR->OnDocumentDataChange(pDoc);
  232.     return;
  233.     }
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242. /*
  243.  * CDocumentAdviseSink::OnCloseRequest
  244.  *
  245.  * Purpose:
  246.  *  A document was closed by the user so we have to effect it here.
  247.  *
  248.  * Parameters:
  249.  *  pDoc            LPCDocument notifying us.
  250.  *
  251.  * Return Value:
  252.  *  None
  253.  */
  254.  
  255. void CDocumentAdviseSink::OnCloseRequest(LPCDocument pDoc)
  256.     {
  257.     LPCFrame    pFR=(LPCFrame)m_pv;
  258.  
  259.     //Ask if you want to save.
  260.     if (!pFR->m_pCL->FCleanVerify(pDoc))
  261.         return;
  262.  
  263.     pFR->m_pCL->CloseDocument(pDoc);
  264.     pFR->UpdateGizmos();
  265.  
  266.     return;
  267.     }
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274. /*
  275.  * CDocumentAdviseSink::OnSizeChange
  276.  *
  277.  * Purpose:
  278.  *  Notifies us that the document was resized.
  279.  *
  280.  * Parameters:
  281.  *  pDoc            LPCDocument notifying us.
  282.  *  pRect           LPRECT of the new document window size.
  283.  *
  284.  * Return Value:
  285.  *  None
  286.  */
  287.  
  288. void CDocumentAdviseSink::OnSizeChange(LPCDocument pDoc, LPRECT pRect)
  289.     {
  290.     LPCFrame    pFR=(LPCFrame)m_pv;
  291.    #ifndef MDI
  292.     RECT        rc;
  293.     DWORD       dwStyle;
  294.    #endif
  295.  
  296.     //We only do this in SDI
  297.    #ifdef MDI
  298.     return;
  299.    #else
  300.     //If we caused this from our own WM_SIZE, skip out.
  301.     if (pFR->m_fSizing)
  302.         return;
  303.  
  304.     //Get the document's screen rectangle.
  305.     GetWindowRect(pDoc->Window(), &rc);
  306.  
  307.     //Adjust for GizmoBar
  308.     rc.top-=pFR->m_cyBar;
  309.  
  310.     //Adjust for StatStrip
  311.     rc.bottom+=CYSTATSTRIP;
  312.  
  313.     //Adjust for our window
  314.     dwStyle=(LPARAM)GetWindowLong(pFR->m_hWnd, GWL_STYLE);
  315.     AdjustWindowRect(&rc, dwStyle, TRUE);
  316.  
  317.     //This causes sizing of all other tools.
  318.     SetWindowPos(pFR->m_hWnd, NULL, rc.left, rc.top, rc.right-rc.left
  319.         , rc.bottom-rc.top, SWP_NOZORDER | SWP_NOACTIVATE);
  320.  
  321.     return;
  322.    #endif
  323.     }
  324.  
  325.  
  326.  
  327.  
  328. /*
  329.  * CDocumentAdviseSink::OnCaptionChange
  330.  *
  331.  * Purpose:
  332.  *  Notifies us that we should update the caption bars used on this
  333.  *  document.
  334.  *
  335.  * Parameters:
  336.  *  pDoc            LPCDocument notifying us.
  337.  *
  338.  * Return Value:
  339.  *  None
  340.  */
  341.  
  342. void CDocumentAdviseSink::OnCaptionChange(LPCDocument pDoc)
  343.     {
  344.     LPCFrame    pFR=(LPCFrame)m_pv;
  345.  
  346.    #ifdef MDI
  347.     pFR->WindowTitleSet(pDoc, TRUE);
  348.    #else
  349.     pFR->WindowTitleSet(pDoc, FALSE);
  350.    #endif
  351.  
  352.     return;
  353.     }
  354.  
  355.  
  356.  
  357.  
  358.  
  359. /*
  360.  * CDocumentAdviseSink::OnActivate
  361.  *
  362.  * Purpose:
  363.  *  Notifies us that we should update any user interface that
  364.  *  depends on the active document.
  365.  *
  366.  * Parameters:
  367.  *  pDoc            LPCDocument notifying us.
  368.  *
  369.  * Return Value:
  370.  *  None
  371.  */
  372.  
  373. void CDocumentAdviseSink::OnActivate(LPCDocument pDoc)
  374.     {
  375.     LPCFrame    pFR=(LPCFrame)m_pv;
  376.  
  377.     pFR->OnDocumentActivate(pDoc);
  378.     return;
  379.     }
  380.